﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;

namespace AiQiuQuan.Sport.Core
{
    /// <summary>
    /// 缓存
    /// </summary>
    public static class CachingExtension
    {
        public static void AddCaching(this IServiceCollection services, IConfiguration configuration, string instace = null)
        {
            var redisConnectionStr = configuration.GetValue<string>("RedisConnStr");
            if (!string.IsNullOrEmpty(redisConnectionStr))
            {
                services.AddEasyCaching(option =>
                {
                    option.UseRedis(redisOption =>
                    {
                        redisOption.DBConfig.Configuration = redisConnectionStr;
                        redisOption.SerializerName = "msgpack";
                        redisOption.DBConfig.KeyPrefix = "aqq:";
                    }, instace ?? "redis");
                    option.WithMessagePack();
                });
            }
        }
    }
}
